const userSigninTpl = require('../views/userSignin.html');

const userSigninController = {
    render({ res, router }) {
        res.render(userSigninTpl);
        this.signin(router);
    },
    signin(router) {
        $('#user-signin').click(() => {
            $.ajax({
                type: "post",
                url: "/interface/user/signin",
                data: {
                    username: $('#signin-username').val(),
                    password: $('#signin-password').val()
                },
                dataType: "json",
                success: function(res) {
                    if (res.rat) {
                        $('#signin-before').hide().siblings('#signin-after').show();
                        $('.username').text($('#signin-username').val());
                        router.go('/index');
                    } else {
                        alert('用户名或密码错误,请重新输入');
                    }
                }
            });
        });
    }
}

module.exports = userSigninController;